package 数组.easy;

import java.util.Arrays;

/**
 * @author Lw中
 * @date 2020/8/4 10:17
 */
public class YiLingBaJiu {

    public static int[] duplicateZeros(int[] arr) {
        int[] temp = Arrays.copyOf(arr, arr.length);
        int index = 0;
        for (int i = 0; i < arr.length; i++) {
            arr[i] = temp[index];
            if (temp[index++] == 0 && i + 1 < arr.length) {
                arr[i + 1] = 0;
                i++;
            }
        }
        return arr;
    }

    public static void main(String[] args) {
        int[] arr = {1,0,2,3,0,4,5,0};
        int[] res = duplicateZeros(arr);
        for (int i = 0; i < res.length; i++) {
            System.out.println(res[i]);
        }
    }
}
